//
//  main.swift
//  
//
//  Created by ZhipengZheng on 2020/6/18.
//

import Foundation
import JAZExcelTool

var path = URL(fileURLWithPath: NSHomeDirectory())
path.appendPathComponent("Desktop")
path.appendPathComponent("value.xlsx")
var fileName = path.path

func writeValue() throws {
    let tool = try ExcelTool(write: fileName, sheetName: "Sheet1")
    tool.writeTitles(values: [("Key", 30), ("Value", 50)])
    for i in 0..<20 {
        tool.writeDatas(values: ["Key\(i)", "Value\(i)"])
    }
}

func readValue() throws {
    let tool = try ExcelTool(read: fileName)
    let sheet = try tool.sheet(at: 0)
    sheet.forEach { (value, row, column, stop) in
        print(value.item ?? "Empty", row, column)
    }
    
    print("[1-1]: ", sheet.string(of: .init(row: 1, column: 1)) ?? "None")
    print("[9-0]: ", sheet.string(of: .init(row: 9, column: 0)) ?? "None")
}

try writeValue()
try readValue()

